#ifndef __MVS_FACTORY_TEST_APIS_H__
#define __MVS_FACTORY_TEST_APIS_H__

#include "mvdef.h"

MVCXX_EXTERN_BEGIN

#include "mvs_core/mvs_core_porting.h"
#include "mvs_core/iotc/mvs_iotc_service.h"

typedef mv_s32_t(*pf_factory_configs_pick)(mv_vptr_t pout, mv_s32_t s32_outmax);
typedef mv_s32_t(*pf_factory_test_config)(mv_cv8ptr_t cpv8_key, mv_s32_t s32_klen, mv_cv8ptr_t cpv8_val, mv_s32_t s32_vlen, mv_u8_t u8_vtype, mv_bool_t bl_flush);
typedef mv_s32_t(*pf_factory_test_action)(mv_cv8ptr_t cpv8_key, mv_s32_t s32_klen, mv_cv8ptr_t cpv8_val, mv_s32_t s32_vlen, mv_vptr_t pout, mv_s32_t s32_outmax);
typedef mv_s32_t(*pf_factory_test_elic_auth)(mv_u32_t u32_did, mv_cv8ptr_t cpv8_model_name, mv_vptr_t pin, mv_vptr_t pout, mv_s32_t s32_outmax);

typedef struct _factory_mqtt_args
{
    mv_u8_t          au8_outbuf[256];     ///< 数据缓存
    mv_cv8ptr_t      cpv8_url;            ///< url
    mv_u8ptr_t       pu8_cid;             ///< 客户端标识
    mv_u8ptr_t       pu8_usr;             ///< 连接用户名
    mv_u8ptr_t       pu8_pwd;             ///< 连接密码(用户名不存在时，无效)
    mv_u16_t         u16_cid_len;         ///< 客户端标识长度
    mv_u16_t         u16_usr_len;         ///< 连接用户名长度
    mv_u16_t         u16_pwd_len;         ///< 连接密码长度
}factory_mqtt_args_t;

typedef struct _spec_args
{
    mv_u32_t         u32_vdid;            ///< 虚拟DID
    mv_cv8ptr_t      cpv8_sign_str;       ///< 工装signature
    mv_cv8ptr_t      cpv8_spec_data;      ///< 特定设备非固定协议数据
    mv_u16_t         u16_spec_len;        ///< 特定设备非固定协议数据长度
    mv_u8_t          u8_spec_type;        ///< 特点设备非固定协议类型[mvs_ft_spec_e]
    mv_u8_t          u8_cfgs;             ///< 厂测配置应用情况
    mv_u8_t          u8_ble_result;       ///< BLE测试结果
}factory_spec_args_t;

typedef struct _factory_test_init_args {
    mv_cv8ptr_t               cpv8_spec_model_name;
    mv_cv8ptr_t               cpv8_spec_product_name;
    pf_factory_configs_pick   f_cfgs_pick_resolve;
    pf_factory_test_config    f_cfg_resolve;
    pf_factory_test_action    f_act_resolve;
    pf_factory_test_elic_auth f_elic_auth_resolve;
    factory_spec_args_t       spec_args;
    factory_mqtt_args_t       mq_args;
}iotc_factory_test_init_args_t;

/** 非厂测模式下，最小初始化（需要用到回调函数） */
mv_s32_t mvs_core_factory_test_sinit(iotc_factory_test_init_args_t *pargs);

/** 厂测模式下，完整初始化 */
mv_s32_t mvs_core_factory_test_init(iotc_factory_test_init_args_t *pargs);

mv_s32_t mvs_core_factory_test_set_cloudsPDID(mv_u32_t u32_pdid);

/**
 * @brief 厂测新烧录license应用刷新
 * 
 * @param pstru_args [in] 初始化参数（只需要license部分）
 * @return 刷新结果
 * -   success: MV_EC_SUCCESS
 * -    failed: MV_EC_PERMS_DENIED (加密权限不足运行本设备)
 */
mv_s32_t mvs_core_factory_test_license_update(mvs_iotc_svc_args_t *pstru_args);

MVCXX_EXTERN_END

#endif
